/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utility;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Map.Entry;
import org.apache.hadoop.io.WritableComparable;

/**
 *
 * @author takeshi
 */
public class NestLonPair implements WritableComparable<NestLonPair> {

    Long key;
    LongPair val;

    public NestLonPair(Long key, LongPair val) {
        this.key = key;
        this.val = val;
    }

        public NestLonPair(int key, LongPair val) {
        this.key =  (long) key;
        this.val = val;
    }

    public NestLonPair() {
        this.key = 0l;
        this.val = new LongPair(0, 0);
    }

    public long getFirst() {
        return key;
    }

    public LongPair getSecond() {
        return val;
    }

    public void write(DataOutput out) throws IOException {
        out.writeLong(key);
        out.writeLong(val.getFirst());
        out.writeLong(val.getSecond());
    }

    public void readFields(DataInput in) throws IOException {
          key = in.readLong();
     //      val.setFirst(in.readLong()) ;
      //     val.setSecond(in.readLong() );
    }

      public static int compare(long a, int b) {
    return (a < b ? -1 : (a == b ? 0 : 1));
  }

    public static int compare(int a, long b) {
    return (a < b ? -1 : (a == b ? 0 : 1));
  }

    public static int compare(long a, long b) {
    return (a < b ? -1 : (a == b ? 0 : 1));
  }
    
    public int compareTo(NestLonPair ip) {
        int cmp = compare(key, ip.getFirst());
        if (cmp != 0) {
            return cmp;
        }
        return val.compareTo(ip.getSecond()) ;
    }
}
